package cn.ssm.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import cn.ssm.pojo.User;
import cn.ssm.tools.Constants;

public class SysIntercetor extends HandlerInterceptorAdapter {
	private Logger logger = Logger.getLogger(SysIntercetor.class);
	public boolean preHandle(HttpServletRequest request,
			HttpServletResponse response, Object handler)throws Exception {
		logger.debug("SysInterceptor preHandle!");
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute(Constants.USER_SESSION);
		if(user ==null){
			response.sendRedirect(request.getContextPath()+"/error.jsp");
			return false;
		}
		return true;
	}
}
